import groovy.sql.Sql



packageDir = new File("/home/mephisto/data/SRPMS/")

packages = packageDir.listFiles()

set  = new TreeSet()
for (pkg in packages)
    set.add(pkg.getAbsolutePath())
    
for (pkgp in set) {
 
 pkg = new File(pkgp)
 pkgName = pkg.getName()
 dir = stringToInteger(pkgName)
 newFile = new File("/home/mephisto/data/$dir/$pkgName")
 success = newFile.mkdirs()
 if (success) {
     success = pkg.renameTo(newFile)
     println "$pkgName moved to $dir: $success"
 }
}

def void log(String message) {

    date = new Date()
    message = date.toString()+" "+message
    println message
    log.append("$date $message\n")
}


//select floor(length(package)/ASCII(package)*1000) as v, count(package) as c from PACKAGES group by v order by c,v;

def int stringToInteger(String str) {
    
    //floor(length(package)/ASCII(package)*1000)
    length = str.length()
    code = (int)str.substring(0,1)
    value = Math.floor(length/code * 1000)
    return value

}
